package com.ls.demo.controller;

import com.ls.demo.common.Result;
import com.ls.demo.common.enums.RoleEnum;
import com.ls.demo.entity.Account;
import com.ls.demo.entity.Admin;
import com.ls.demo.entity.SuperAdmin;
import com.ls.demo.service.AdminService;
import com.ls.demo.service.StudentService;
import com.ls.demo.service.SuperAdminService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
public class WebController {
//    @Resource
//    private SuperAdminService superAdminService;
//    @GetMapping("/")
//    public Result hello(){
//        return Result.success();
//    }
//    @PostMapping("/login")
//    public Result login(@RequestBody SuperAdmin superAdmin){
//        Account loginAccount =null;
//        if(RoleEnum.SUPER_ADMIN.name().equals(superAdmin.getRole())){
//            loginAccount =  superAdminService.login(superAdmin);
//        }
//        return Result.success(loginAccount);
//    }
    @Resource
    private AdminService adminService;
    @Resource
    private StudentService studentService;
    @PostMapping("/login")
    public Result login(@RequestBody Account account) {
        Account loginAccount = null;
        if (RoleEnum.SUPER_ADMIN.name().equals(account.getRole())||RoleEnum.COLLEGE_ADMIN.name().equals(account.getRole())||RoleEnum.SCIENCE_ADMIN.name().equals(account.getRole())) {
            loginAccount = adminService.login(account);
        } else if (RoleEnum.STUDENT.name().equals(account.getRole())){
            loginAccount = studentService.login(account);
        }
        return Result.success(loginAccount);
    }
    /**
     * 修改密码
     */
    @PutMapping("/updatePassword")
    public Result updatePassword(@RequestBody Account account) {
        if (RoleEnum.SUPER_ADMIN.name().equals(account.getRole())||RoleEnum.COLLEGE_ADMIN.name().equals(account.getRole())||RoleEnum.SCIENCE_ADMIN.name().equals(account.getRole())) {
            adminService.updatePassword(account);
        } else if (RoleEnum.STUDENT.name().equals(account.getRole())) {
            studentService.updatePassword(account);
        }
        return Result.success();
    }
}
